package evaluatetask

import (
	dbModel "ZHONGYIHANGYAN/bean/dbModel"
	"ZHONGYIHANGYAN/mysql"
	"context"
	"sync"
)

// 任务监控信息
type TaskMonitor struct {
	TaskId     string
	Cancel     context.CancelFunc
	IsActive   bool
}

// 倒计时信息
type FinalScoreCountdown struct {
	TaskId     string
	Cancel     context.CancelFunc
	IsActive   bool
}

type EvaluateTaskManage struct {
	mysql.DataBase
	// 任务监控管理器
	monitors sync.Map // map[string]*TaskMonitor
	// 倒计时管理器
	countdowns sync.Map // map[string]*FinalScoreCountdown
}

var defaultEvaluateTaskManage = &EvaluateTaskManage{}

func Manage() *EvaluateTaskManage {
	return defaultEvaluateTaskManage
}

// 初始化指标表
func InitTable(DB *mysql.MysqlGorm) {
	defaultEvaluateTaskManage.DataBase = DB
	defaultEvaluateTaskManage.autoMigrate()
}

func (m *EvaluateTaskManage) autoMigrate() {
	m.DataBase.AutoMigrate(&dbModel.EvaluateTask{})
}
